package com.arouter.demo.searchmodule.uri;

import android.annotation.SuppressLint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.arouter.demo.baselib.router.RouterPath;
import com.arouter.demo.searchmodule.R;
import com.arouter.demo.searchmodule.entity.ObjEntity;

/**
 *
 * 解系URL中的参数
 * <p>
 * 需要为每个参数声明一个字段，并使用 @Autowired 标注
 * URL中不能传递 Parcelable类型数据，通过ARouter api可以传递Parcelable对象
 */
@Route(path = RouterPath.URI_TEST_FIRST)
public class UriTestFirstActivity extends AppCompatActivity {
    @Autowired
    String name;
    @Autowired
    String age;
    @Autowired(name = "boy")
    boolean girl;
    @Autowired
    String high;

    // 未序列化的对象，URL中不能传递 Parcelable类型数据
    @Autowired(name = "obj")
    ObjEntity objEntity;


    @SuppressLint("SetTextI18n")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uri_test_first);


        TextView tvClassName = findViewById(R.id.class_name);
        tvClassName.setText("I am " + UriTestFirstActivity.class.getName());

        // 依赖注入
        ARouter.getInstance().inject(this);


        // 解析普通参数
        TextView tvCutomParm = findViewById(R.id.tv_receive_param_value);
        String parseQuery = String.format("name=%s, age=%s, girl=%s, high=%s", name, age, !girl,
                high);
        tvCutomParm.setText(parseQuery);

        // 解析URL中的json字符串,URL中不能传递 Parcelable类型数据
        TextView tvObj = findViewById(R.id.tv_receive_object_value);
        if (objEntity != null) {
            tvObj.setText(objEntity.toString());
        }

    }
}
